package com.hnqcgczy.supplier.service;

import com.hnqcgczy.supplier.dao.MarketDao;
import com.hnqcgczy.supplier.dao.impl.MarketDaoImpl;
import com.hnqcgczy.supplier.db.MyTransaction;
import com.hnqcgczy.supplier.vo.Market;

import java.sql.SQLException;
import java.util.List;

public class MarketServiceImpl implements MarketService {
    //需要事物
    private MyTransaction myTransaction = new MyTransaction(true);
    //需要Dao
    private MarketDao marketDao = new MarketDaoImpl(myTransaction);

    @Override
    public boolean add(Market market) throws SQLException {
        return marketDao.add(market) > 0;
    }

    @Override
    public boolean update(Market market) throws SQLException {
        return marketDao.update(market) > 0;
    }

    @Override
    public boolean delete(Integer marketId) throws SQLException {
        return marketDao.delete(marketId) > 0;
    }

    @Override
    public List<Market> queryByLike(Market market, int pageNow, int pageSize) throws SQLException {
        // 根据当前页算出start
        int start = (pageNow - 1) * pageSize;
        return marketDao.queryByLike(market, start, pageSize);
    }

    @Override
    public Market findOne(Integer marketId) throws SQLException {
        return marketDao.findOne(marketId);
    }

    @Override
    public int total(Market query) throws SQLException {
        return marketDao.total(query);
    }
}
